package de.godlike.webgui;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

import de.godlike.services.DiskInfo;
import de.godlike.services.UnknownHostException_Exception;
import de.godlike.webgui.internal.BeanManager;

@ManagedBean
@ViewScoped
public class SystemInfoBean {
	private final JWebminBean sessionBean = BeanManager.findBean("jWebminBean",
			JWebminBean.class);
	private List<DiskInfo> diskList;
	private String osType;

	public SystemInfoBean() {
	}

	/**
	 * @return the osType
	 */
	public String getOsType() {
		if (this.osType == null) {
			this.osType = this.sessionBean.getService().getOsType();
		}
		return this.osType;
	}

	public String getArch() {
		return this.sessionBean.getService().getArch();
	}

	public String getOsVersion() {
		return this.sessionBean.getService().getOsVersion();
	}

	public String getTimeZone() {
		return this.sessionBean.getService().getTimeZone();
	}

	public String getSystemName() {
		return this.sessionBean.getService().getSystemName();
	}

	public String getSystemIp() {
		try {
			return this.sessionBean.getService().getSystemIp();
		} catch (UnknownHostException_Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "Unknown";
	}

	public void shutdownServer(ActionEvent event) {
		// TODO: Zeit über event übergeben
		this.sessionBean.getService().shutdown(0);
	}

	public void restartServer(ActionEvent event) {
		this.sessionBean.getService().restart();
	}

	public List<DiskInfo> getDiskList() {
		if (this.diskList == null) {
			this.diskList = this.sessionBean.getService().getDiskList();
		}
		return this.diskList;
	}

	public List<String> getJWebminServiceLog() {
		return this.sessionBean.getService().getJWebminServiceLog();
	}
}
